import cv2
import numpy as np

# 读取图像
image = cv2.imread('image.jpg')
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 应用Harris角点检测
gray_image = np.float32(gray_image)
dst = cv2.cornerHarris(gray_image, 2, 3, 0.04)

# 膨胀结果以突出显示角点
dst = cv2.dilate(dst, None)

# 设置阈值以标记角点
image[dst > 0.01 * dst.max()] = [0, 0, 255]  # 用红色标记角点

# 显示结果
cv2.imshow('Harris Corners', image)
cv2.waitKey(0)
cv2.destroyAllWindows()